import urllib
import re
import os

from OGameError import OGameError

class OGame:
    def __init__(self, username, password, server=None): 
        self.username = username
        self.password = password
        self.logged_in = false
        if server:
            self.login(server)
        
    def get_servers(self):
        ''' Returns all available universes as a dictionary
            {server name: server URL}. If you know the URL of your universe,
            it's better to not use this function. '''
        data = urllib.urlopen('http://www.ogame.org').read()
        data = re.sub('[\s]', '', data)
        servers_raw = re.findall('<optionvalue="(.*?)".*?>([a-zA-Z0-9. ]+)<\/option>',
                                 data)
        servers = {}
        for s in servers_raw:
            servers[s[1]] = s[0]
        return servers
    
    
    def login(self, server):
        ''' Logs in to the universe hosted at 'server' using the username and
            password supplied when creating an instance. '''
        pass
    
    def get_metal(self):
        ''' Returns a tuple containing the current amount of metal, and
            current production rate. Raises an exception if not logged in. '''
        if not self.logged_in:
            raise OGameError, 'Not logged in'
        pass
    
    def get_crystal(self):
        ''' Returns a tuple containing the current amount of crystal, and
            current production rate.  Raises an exception if not logged
            in. '''
        if not self.logged_in:
            raise OGameError, 'Not logged in'
        pass
    
    def get_deuterium(self):
        ''' Returns a tuple containing the current amount of deuterium, and
            current production rate. Raises an exception if not logged in. '''
        if not self.logged_in:
            raise OGameError, 'Not logged in'
        pass
    
    def get_dark_matter(self):
        ''' Returns a tuple containing the current amount of dark matter (you
            rich kid :). Raises an exception if not logged in. '''
        if not self.logged_in:
            raise OGameError, 'Not logged in'
        pass